package com.hzf.wxplatform.web.controller.manager;

import com.hzf.common.base.BaseController;
import com.hzf.common.util.WeixinUtils;
import com.hzf.common.wxgps.WxGps;
import com.hzf.wxplatform.common.utils.WxGetGpsUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;

/**
 * describe: TODO
 * creat_user: 白开水
 * creat_time: 2017/11/24   16:16
 **/
@Controller
@RequestMapping("/weixin")
public class WxTokenCodeController {
    //获取微信支付，2017/12/12 08：00  用于获取
    @RequestMapping(value="/loginByWechat",method = RequestMethod.GET)
    public void lohinaByWechat(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("123456");
        String signature = request.getParameter("signature");
                // 时间戳
                String timestamp = request.getParameter("timestamp");
                // 随机数
                String nonce = request.getParameter("nonce");
                // 随机字符串
                String echostr = request.getParameter("echostr");

                PrintWriter out = response.getWriter();
                // 通过检验signature对请求进行校验，若校验成功则原样返回echostr，表示接入成功，否则接入失败
                if (WeixinUtils.checkSignature(signature, timestamp, nonce)) {
                    out.print(echostr);
                    System.out.println("微信服务验证成功！");
                }
            }
    @RequestMapping(value="/loginByWechat",method = RequestMethod.POST)
    @ResponseBody
    public void wechatServicePost(PrintWriter out,HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        out.print("success");
        out.flush();
    }
}
